#include "TestLabelForm.h"



TestLabelForm::TestLabelForm() 
	: m_label1(1), m_label2(6), m_btnLeftAlign(2), m_btnMiddleAlign(3), m_btnRightAlign(4), m_btnWordWrap(5) {

	this->CreatedEvent.Register(this, &TestLabelForm::OnCreated);
	SetSize(400, 300);
}



void TestLabelForm::OnCreated(CreatedEventArgs&) {

	m_btnLeftAlign.SetSize(100, 35);
	m_btnLeftAlign.SetPosition(0, 0);
	m_btnLeftAlign.SetText(L"Left align");
	m_btnLeftAlign.Create();
	m_btnLeftAlign.SetParent(*this);

	m_btnMiddleAlign.SetSize(100, 35);
	m_btnMiddleAlign.SetPosition(100, 0);
	m_btnMiddleAlign.SetText(L"Middle align");
	m_btnMiddleAlign.Create();
	m_btnMiddleAlign.SetParent(*this);

	m_btnRightAlign.SetSize(100, 35);
	m_btnRightAlign.SetPosition(200, 0);
	m_btnRightAlign.SetText(L"Right align");
	m_btnRightAlign.Create();
	m_btnRightAlign.SetParent(*this);

	m_label1.SetSize(300, 35);
	m_label1.SetPosition(50, 50);
	m_label1.SetText(L"I'm a label!");
	m_label1.Create();
	m_label1.SetParent(*this);

	m_btnWordWrap.SetSize(100, 35);
	m_btnWordWrap.SetPosition(0, 90);
	m_btnWordWrap.SetText(L"Word wrap");
	m_btnWordWrap.SetParent(*this);
	m_btnWordWrap.Create();

	m_label2.SetSize(100, 35);
	m_label2.SetPosition(50, 150);
	m_label2.SetText(L"I'm a label!!!!!!!!!!!!!!!!!!");
	m_label2.SetParent(*this);
	m_label2.Create();
}



LRESULT TestLabelForm::WndProc(const WndMsg& msg) {

	if (msg.Message == WM_COMMAND) {

		if (msg.WParamHigh == BN_CLICKED) {

			if (msg.WParamLow == m_btnLeftAlign.GetID()) {
				m_label1.SetTextAlign(TextAlign::Left);
			}
			else if (msg.WParamLow == m_btnMiddleAlign.GetID()) {
				m_label1.SetTextAlign(TextAlign::Center);
			}
			else if (msg.WParamLow == m_btnRightAlign.GetID()) {
				m_label1.SetTextAlign(TextAlign::Right);
			}
			else if (msg.WParamLow == m_btnWordWrap.GetID()) {
				m_label2.IsWordWrap( ! m_label2.IsWordWrap());
			}
		}
	}

	return Form::WndProc(msg);
}